package com.ease.map.task.analysis
{
   import com.kgis.flexutil.RemoteService;
   import com.kgis.flexutil.ServiceUtil;
   import com.ease.map.Map;
   import com.ease.map.RemoteCaller;
   import com.ease.map.common.enum.SpatialOperatorEnum;
   import com.ease.map.geometry.IGeometry;
   import com.ease.map.geometry.basetype.Extent;
   import com.ease.map.layer.LayerData;

   import flash.external.ExternalInterface;
   import flash.net.getClassByAlias;
   import flash.net.registerClassAlias;
   import flash.utils.describeType;
   import flash.utils.getDefinitionByName;
   import flash.utils.getQualifiedClassName;

   import mx.controls.Alert;
   import mx.rpc.AsyncResponder;
   import mx.rpc.AsyncToken;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import com.ease.map.task.analysis.SpatialAnalysis;

   /**
    * spatial analysis by geometry
    */
   public class SpatialAnalysisByGeometry extends SpatialAnalysis {
      //分析图层id
      private var _layerId:Number;
      //空间分析几何体
      private var _geometry:IGeometry;

      private var _spatialOperator:String;

      private var _starttime:Date;

      public function SpatialAnalysisByGeometry(layerId:Number,geometry:IGeometry,spatialOperator:String=SpatialOperatorEnum.ANYINTERACT) {
         this._layerId = layerId;
         this._geometry = geometry;
         this._spatialOperator = spatialOperator;

         super("spatialQueryByGeometry");
      }

      override public function execute():void {
         if (null == onResult)
            return;
         _starttime = new Date();
         var remoteCaller:RemoteCaller = new RemoteCaller("spatialDataAnalyzeManagementService")
         var token:AsyncToken = remoteCaller.remoteObject.getOperation(operationName).send(geometry,layerId, spatialOperator);
         token.addResponder(new AsyncResponder(onAnalysisResult, onAnalysisFault));
      }

      /**根据图层id和geometry空间分析矢量设施数据*/
      private function onAnalysisResult(event:ResultEvent, token:Object = null):void {
         var layerData:LayerData = event.result as LayerData;
         trace("layerid:" + layerId.toString() + ",remote请求耗时:" + ((new Date()).getTime() - _starttime.getTime()).toString());
         onResult(layerData, token);
      }

      public function get layerId():Number {
         return _layerId;
      }

      public function set layerId(value:Number):void {
         _layerId = value;
      }

      public function get spatialOperator():String
      {
         return _spatialOperator;
      }

      public function set spatialOperator(value:String):void
      {
         _spatialOperator = value;
      }

      public function get geometry():IGeometry
      {
         return _geometry;
      }

      public function set geometry(value:IGeometry):void
      {
         _geometry = value;
      }


   }
}